﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HS.Domain.EF;
using System.Data.Entity;

namespace HS.Business.Security
{
    public class CondicionBusiness
    {
        public Condicion CreateEntity()
        {
            return new Condicion()
            {
                Subcondiciones = new List<Subcondicion>(),
                RowStatus = true
            };
        }

        public Condicion GetEntityByPK(int? idCondicion, bool? rowStatus)
        {
            HomeSolutionsDBEntities context = new HomeSolutionsDBEntities();

            var dbset = context.Set<Condicion>();

            return dbset.Include(p => p.Subcondiciones)
                        .Where(p => p.IdCondicion == idCondicion
                                && (rowStatus != null ? p.RowStatus == rowStatus : p.RowStatus == true))
                        .FirstOrDefault();
        }

        public List<Condicion> GetEntities(int? idCondicion, bool? rowStatus)   //TODO: agregar filtros
        {
            HomeSolutionsDBEntities context = new HomeSolutionsDBEntities();

            var dbset = context.Set<Condicion>();

            return dbset.Include(p => p.Subcondiciones)
                        .Where(p => p.IdCondicion == idCondicion
                                && (rowStatus != null ? p.RowStatus == rowStatus : p.RowStatus == true))
                        .ToList();
        }
    }
}
